using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_JXC_SearchReceiptMoney : Member, IRequiresSessionState
{
	private string linkHead = "";
	protected Literal ltrTitle;
	protected TextBox txtSearchBuyerName;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected Button btnSearch;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerFinancemanage(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.BindData();
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("BuyerName");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBuyerName.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBuyerName.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and o.BuyerName like '%" + text2 + "%'";
			this.linkHead = this.linkHead + "&BuyerName=" + text2;
		}
		string text3 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchBeginDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and DATEDIFF(DD, ReceiptDate,'" + text3 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text3;
		}
		string text4 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchEndDate.Text = text4;
		}
		else
		{
			text4 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			if (!string.IsNullOrEmpty(text3))
			{
				if (Convert.ToDateTime(text3) > Convert.ToDateTime(text4))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, ReceiptDate,'" + text4 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text4;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by sio.InfoOrderID desc";
		string value = this.txtSearchBeginDate.Text.Trim();
		string value2 = this.txtSearchEndDate.Text.Trim();
		if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2))
		{
			result = "order by ReceiptDate desc";
		}
		return result;
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLJXC_StockInfoOrder as sio,HLShop_Order as o where  o.OrderFormID=sio.OrderID and (StockOrderType<>'xsgjd') and o.SalerID=" + base.user.UserID + " ";
		int num2 = 10;
		int listCount = BLLInstance.BllClientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,o.BuyerName,sio.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = BLLInstance.BllClientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.rptList.DataSource = listPage;
		this.rptList.DataBind();
		decimal d = 0m;
		decimal d2 = 0m;
		decimal d3 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			int num3 = i + 1;
			if (num > 0)
			{
				num3 = (num - 1) * num2 + num3;
			}
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			label.Text = num3.ToString();
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblReceiptMoney");
			Label label3 = (Label)this.rptList.Items[i].FindControl("lblAlreadyReceiptMoney");
			Label label4 = (Label)this.rptList.Items[i].FindControl("lblNoReceiptMoney");
			if (label4 != null)
			{
				if (!string.IsNullOrEmpty(label2.Text) && !string.IsNullOrEmpty(label3.Text))
				{
					decimal num4 = Convert.ToDecimal(label2.Text);
					decimal d4 = Convert.ToDecimal(label3.Text);
					label4.Text = (num4 - d4).ToString();
					d += num4;
					d2 += d4;
					d3 += Convert.ToDecimal(label4.Text);
				}
			}
		}
		Label label5 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalReceiptMoney");
		Label label6 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalAlreadyReceiptMoney");
		Label label7 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalNoReceiptMoney");
		label5.Text = d.ToString();
		label6.Text = d2.ToString();
		label7.Text = d3.ToString();
		string url = "SearchReceiptMoney.aspx?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, num2, listCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url, true);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
